/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package music.global;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.font.LineMetrics;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.util.TreeMap;

/**
 *
 * @author TJ
 */
public class CharacterMap {
    //Clefs
    public static final char G_CLEF=0xF026;
    public static final char BASS_CLEF=0xF03F;
    public static final char C_CLEF=0xF042;
    //Time
    public static final char COMMON_TIME=0xF063;
    public static final char CUT_TIME=0xF026;
    public static final char ZERO=0xF026;
    //Notes
    public static final char _128_NOTE=0xF078;
    public static final char _64_NOTE=0xF078;
    public static final char _32_NOTE=0xF078;
    public static final char SIXTEENTH_NOTE=0xF078;
    public static final char EIGTH_NOTE=0xF065;
    public static final char QUARTER_NOTE=0xF071;
    public static final char HALF_NOTE=0xF068;
    public static final char WHOLE_NOTE=0xF077;
    public static final char DOUBLE_WHOLE_NOTE=0xF057;
    //Down stem Notes
    public static final char SIXTEENTH_NOTE_DOWN=0xF026;
    public static final char EIGTH_NOTE_DOWN=0xF026;
    public static final char QUARTER_NOTE_DOWN=0xF026;
    public static final char HALF_NOTE_DOWN=0xF026;
    //Rests
    public static final char _128_REST=0xF0E5;
    public static final char _64_REST=0xF0F4;
    public static final char _32_REST=0xF0A8;
    public static final char SIXTEENTH_REST=0xF0C5;
    public static final char EIGTH_REST=0xF0E4;
    public static final char QUARTER_REST=0xF0CE;
    public static final char HALF_REST=0xF0B7;
    public static final char WHOLE_REST=0xF0B7;
    //sharps/flats
    public static final char DOUBLE_FLAT=0xF0BA;
    public static final char FLAT=0xF062;
    public static final char NATURAL=0xF06E;
    public static final char SHARP=0xF023;
    public static final char DOUBLE_SHARP=0xF0DC;
    //noteheads
    //flags
    //Bars/stems
    public static final char UPBOW=0xF026;
    public static final char DOWNBOW=0xF026;
    public static final char STACCATO=0xF02E;
    public static final char LEGATO=0xF02D;
    public static final char CAP=0xF05E;
    public static final char ACCENT=0xF03E;
    //Accents
    //Dynamics
    
    //Lines
    //Symbols
    public static final char FERMATA=0xF026;
    public static final char DOWNFERMATA=0xF026;
    //public static final char STACCATO=0xF026;
    public static int getWidth(char c, Font f) {
        FontMetrics m=Toolkit.getDefaultToolkit().getFontMetrics(f);
        return m.charWidth(c);
    }
    public static Image getImage(Font f2, String c) {
        if(c.length()==0){return null;}
        BufferedImage i2=new BufferedImage(100,100,BufferedImage.TYPE_INT_ARGB);
        Graphics2D g=((Graphics2D)i2.getGraphics());
        g.setFont(f2);
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        FontMetrics f=g.getFontMetrics();
        Rectangle2D b=f.getStringBounds(c,g);
        LineMetrics l=f.getLineMetrics(c, g); 
        
        //g.clearRect(0, 0, 100, 100);
        i2=new BufferedImage((int)b.getWidth()+1,(int)(l.getAscent()),BufferedImage.TYPE_INT_ARGB);       
        g=((Graphics2D)i2.getGraphics());
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setFont(f2);
        g.setColor(Color.BLACK);
        g.drawString(c, 0, (int)(l.getHeight()-l.getAscent()));
        /*((Graphics2D)i2.getGraphics()).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        i2.getGraphics().setFont(f2);
        
        Rectangle2D b=f.getStringBounds(""+c, i2.getGraphics());
         
       *///g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        //
        //g.drawString(""+(char)CharacterMap.G_CLEF, 0, 0);
        return i2;
    }
}
